/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package manager;

import entity.Comment;
import entity.Comments;
import entity.ConnectDB;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import marshall.GenXML;

/**
 *
 * @author tiz
 */
public class CommentsManager {
    public CommentsManager(){}

    public Comments getCommentsDB() {
        try {
            Comments cList = new Comments();
            Comment comment = null;
            ConnectDB con = new ConnectDB();
            Connection connection = con.getCon();
            Statement stm = connection.createStatement();

//            String query = "SELECT * FROM Films WHERE Name like '%" + filmName + "%'";
            String query = "SELECT * FROM Comments";
            ResultSet rs = stm.executeQuery(query);
            while (rs.next()) {
                String cmtID = rs.getString(1);
                String userID = rs.getString(2);
                String cmt = rs.getString(3);
                comment = new Comment(cmtID,userID,cmt);
                cList.setComment(comment);
            }
            return cList;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void commentsToXML(String filename) {
        CommentsManager cm = new CommentsManager();
        Comments cList = new Comments();
        cList = cm.getCommentsDB();

        GenXML genxml = new GenXML();
        genxml.mar(cList, filename);
    }

}
